Modern Asynchronous JavaScript by Faraz K. Kelhini

Modern Asynchronous JavaScript by Faraz K. Kelhini

Author:Faraz K. Kelhini [Faraz K. Kelhini]
Language: eng
Format: epub
Publisher: Pragmatic Bookshelf
Published: 2021-12-17T00:00:00+00:00


Wrapping Up

In this chapter, we looked at potential pitfalls when executing multiple promises at the same time. We learned why looping over asynchronous tasks could be a bad idea because it will cause the promises to run sequentially. Then we learned about the Promise.allSettled() method and compared it to Promise.all().

While Promise.all() is very strict in its execution policy, Promise.allSettled() is forgiving. That doesn’t mean Promise.allSettled() is superior to Promise.all(): they complement each other. Using Promise.all() is more appropriate when you have essential async tasks that are dependent on each other. On the other hand, Promise.allSettled() is more suitable for async tasks that might fail but are not essential for your program to function.

As of ES2021, the ECMAScript standard includes one more method for the promise object: Promise.any(). This method is the opposite of Promise.all(). In the next chapter, we’re going to learn how Promise.any() can help you when you need to focus on the promise that resolves first.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.